import pytest
import os
from mindspore import default_config


def SKIP_ENV_DAVINCI_EXECUTOR(reason='skip when backend is ms_ascend'):
    skip = False
    backend = default_config.__backend__
    if backend == 'ms':
        if 'CONTEXT_DEVICE_TARGET' not in os.environ:
            skip = True
        elif os.environ['CONTEXT_DEVICE_TARGET'] == 'Ascend':
            skip = True
    return pytest.mark.skipif(condition=skip, reason=reason)


def SKIP_ENV_GPU(reason='skip when target is GPU'):
    skip = False
    if 'CONTEXT_DEVICE_TARGET' in os.environ:
        skip = os.environ['CONTEXT_DEVICE_TARGET'] == 'GPU'
    return pytest.mark.skipif(condition=skip, reason=reason)


def SKIP_ENV_CPU(reason='skip when target is CPU'):
    skip = False
    if 'CONTEXT_DEVICE_TARGET' in os.environ:
        skip = os.environ['CONTEXT_DEVICE_TARGET'] == 'CPU'
    return pytest.mark.skipif(condition=skip, reason=reason)
